<?php
/**
 * 服务入口
 */
namespace App;

class EntryService
{
    public $_code = 0;

    public $_msg = '';

    public $_res_data = [];

    private $_fd;

    private $_tag;

    private $_data;

    /**
     *
     * TagEventService constructor.
     * @param $server
     * @param $fd
     * @param string $tag 判断类型
     * @param array $data 数据
     */
    public function __construct($server,$fd,string $tag, array $data){
        $this->_fd     = $fd;
        $this->_tag    = $tag;
        $this->_data   = $data;

        $class_name = 'app\\Service\\' . ucfirst($this->_tag) . 'Service';

        if (class_exists($class_name)){
            $res_service = (new $class_name($server,$this->_fd,$this->_data))->init();
            if (isset($res_service[0]) && is_numeric($res_service[0])){
                $this->_code = $res_service[0];
            }else{
                $this->_code = -300;
            }

            if (isset($res_service[1]) && is_string($res_service[1])){
                $this->_msg = $res_service[1];
            }else{
                $this->_code = '返回异常';
            }

            $this->_res_data = $res_service[2] ?? [];

        }else{
            $this->_code = -200;
            $this->_msg = '类'.$class_name.'不存在';
        }
    }
}